package com.doucat.support.fast.table;

import android.content.Context;
import android.content.res.Resources;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.doucat.support.component.recycle.adapter.CommonRecyclerAdapter;
import com.doucat.support.component.recycle.holder.BaseRecyclerHolder;
import com.tonly.doucatlibrary.R;

import java.util.List;

public class WorkAdapter extends CommonRecyclerAdapter<WorkItem> {
    private int[] colors=new int[]{R.drawable.work_blue,R.drawable.work_yellow,R.drawable.work_green};
    private Resources resources;

    public WorkAdapter(Context context, List<WorkItem> data) {
        super(context, data);
        resources=context.getResources();
    }

    @Override
    public void onBindItemViewHolder(BaseRecyclerHolder holder, int position) {
        WorkItem bean=getItem(position);
        TextView tvName= holder.getView(R.id.tvName);
        tvName.setText(bean.name);

        ImageView imvWork= holder.getView(R.id.imvWork);
        imvWork.setBackground(context.getDrawable(colors[position%3]));
        try{
            int res = resources.getIdentifier(bean.icon,"mipmap",context.getPackageName());
            Glide.with(context).load(res).into(imvWork);
        }catch (Exception e){
//            Glide.with(context).load(R.mipmap.ic_launcher).into(imvWork);
        }
    }

    @Override
    protected int getLayoutRes() {
        return R.layout.item_work;
    }
}
